<?

function tags_user_topLevelFilter($v) { return !$v['filter']['hidden']; }

function tags_user_topLevelTags($data, $base = '', $level=1) {
	
	$num = 0;
	
	foreach ($data as $k => $v)
		if (($v['attr'] & AA_VISIBLE) && !$v['filter']['hidden']) {				// tag is visible
			if ($v['attr'] & AA_SELECTABLE) {		// tag can be selected
				if ($v['filter']['active']) {						// tag isn't filtered out
					if ($v['filter']['current']) {						// tag isn't filtered out
						if ($v['filter']['theOne']) {
							?><li class="tagL<?=$level?>"><span class="tag<?=++$num?> current"><?=$v['name']?></span> <?
						} else {
							?><li class="tagL<?=$level?>"><a class="tag<?=++$num?> current" href="<?=$base?>tag-<?=$v['id']?>/" title="<?=$v['name']?>"><?=$v['name']?></a> <?
						}
					} else {
						?><li class="tagL<?=$level?>"><a class="tag<?=++$num?>" href="<?=$base?>tag-<?=$v['id']?>/" title="<?=$v['name']?>"><?=$v['name']?></a> <?
					}
				} else {
					?><li class="tagL<?=$level?>"><span class="tag<?=++$num?> inactive"><?=$v['name']?></span> <?
				}
			} else {
				?><li class="tagL<?=$level?>"><span class="tag<?=++$num?>"><?=$v['name']?></span> <?
			}

			if($v['filter']['current'] && $v['data']) {
				?><ul><?	tags_user_topLevelTags($v['data'], $base, $level+1) ?></ul><?
			}
			
			?></li><?
		}
}


$base = isset($DATA['tagBaseUrl']) ? $DATA['tagBaseUrl'] : '';

if (sizeof($DATA['tags'])) {
	$d = array_filter($DATA['tags'], "tags_user_topLevelFilter");


	if (sizeof($d) == 1) {
		$d = array_shift($d);
		$d = $d['data'];
	}

	?><ul><? tags_user_topLevelTags($d, $base) ?></ul><?
}